/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdminProdukte.java
 *
 * Created on 30.05.2009, 12:56:13
 */

package Tabs;

import Binding.Binder;
import Binding.GreaterThenRule;
import Binding.RequiredRule;
import BusinessLayer.BusinessLayer;
import logging.Logger;
import Objekte.ProduktListModel;
import Objekte.Produkt;
import dialogs.NewProduct;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;
import net.sf.cglib.core.Local;
import wisi.WiSiApp;
import wisi.WiSiView;

/**
 *
 * @author benji
 */
public class AdminProdukte extends javax.swing.JPanel {
    private ProduktListModel produktModel;
    private Binder binder = new Binder();
    /** Creates new form AdminProdukte */
    public AdminProdukte() {
        initComponents();

       
        Logger.trace("Lade " + this.getName());

        produktModel = new ProduktListModel();
        this.jTable1.setModel(produktModel);
    }

    /**
     * Produkt liste von ALLEN Produkte holen und anzeigen
     */
    public void BindTo() {
        try{
            if(!BusinessLayer.isLoggedIn())return;
            Logger.debug("BindTo");
            produktModel.setData(BusinessLayer.GetProductList());
        }
        catch(Exception e){
            Logger.error("BindTo - Products", e);
        }

    }

    /**
     * Liste der gesuchten Produkte anzeigen
     * @param searchedList
     */
    private void BindTo(ArrayList<Produkt> searchedList) {
        try{
            if(!BusinessLayer.isLoggedIn())return;
            Logger.debug("BindTo mit suchListe");
            produktModel.setData(searchedList);
        }
        catch(Exception e){
            Logger.error("BindTo - Products", e);
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();
        preisTextField = new javax.swing.JTextField();
        beschreibungTextField = new javax.swing.JTextField();
        rankTextField = new javax.swing.JTextField();
        saveButton = new javax.swing.JButton();
        idLabel = new javax.swing.JLabel();
        deleteButton = new javax.swing.JButton();
        startAuctionButton = new javax.swing.JButton();
        auctionTTLSpinner = new javax.swing.JSpinner();
        jLabel9 = new javax.swing.JLabel();
        jSpinner1 = new javax.swing.JSpinner();
        jLabel7 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        produktStatistikLabel = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabelForIcon = new javax.swing.JLabel();
        newButton = new javax.swing.JButton();
        sucheNameTextField = new javax.swing.JTextField();
        suchePreisTextField = new javax.swing.JTextField();
        searchButton = new javax.swing.JButton();
        RefreshButton = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        Calendar calendar = Calendar.getInstance();
        SpinnerModel model = null;

        Date initDate = calendar.getTime();
        calendar.add(Calendar.YEAR, -100);
        Date earliestDate = calendar.getTime();
        calendar.add(Calendar.YEAR, 200);
        Date latestDate = calendar.getTime();
        model = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);
        jSpinnerVonJahr = new javax.swing.JSpinner(model);
        Calendar cal = Calendar.getInstance();
        SpinnerModel mod = null;

        Date date = cal.getTime();
        cal.add(Calendar.YEAR, -100);
        Date startDate = cal.getTime();
        cal.add(Calendar.YEAR, 200);
        Date endDate = cal.getTime();
        mod = new SpinnerDateModel(date,
            startDate,
            endDate,
            Calendar.YEAR);
        jSpinnerBisJahr = new javax.swing.JSpinner(mod);

        setName("Form"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel1.setName("jPanel1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(wisi.WiSiApp.class).getContext().getResourceMap(AdminProdukte.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        nameTextField.setText(resourceMap.getString("nameTextField.text")); // NOI18N
        nameTextField.setName("nameTextField"); // NOI18N

        preisTextField.setText(resourceMap.getString("preisTextField.text")); // NOI18N
        preisTextField.setName("preisTextField"); // NOI18N

        beschreibungTextField.setText(resourceMap.getString("beschreibungTextField.text")); // NOI18N
        beschreibungTextField.setName("beschreibungTextField"); // NOI18N

        rankTextField.setText(resourceMap.getString("rankTextField.text")); // NOI18N
        rankTextField.setName("rankTextField"); // NOI18N

        saveButton.setText(resourceMap.getString("saveButton.text")); // NOI18N
        saveButton.setName("saveButton"); // NOI18N
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        idLabel.setText(resourceMap.getString("idLabel.text")); // NOI18N
        idLabel.setName("idLabel"); // NOI18N

        deleteButton.setText(resourceMap.getString("deleteButton.text")); // NOI18N
        deleteButton.setName("deleteButton"); // NOI18N
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        startAuctionButton.setText(resourceMap.getString("startAuctionButton.text")); // NOI18N
        startAuctionButton.setName("startAuctionButton"); // NOI18N
        startAuctionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startAuctionButtonActionPerformed(evt);
            }
        });

        auctionTTLSpinner.setName("auctionTTLSpinner"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jSpinner1.setName("jSpinner1"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        produktStatistikLabel.setText(resourceMap.getString("produktStatistikLabel.text")); // NOI18N
        produktStatistikLabel.setName("produktStatistikLabel"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jLabelForIcon.setText(resourceMap.getString("jLabelForIcon.text")); // NOI18N
        jLabelForIcon.setName("jLabelForIcon"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(idLabel))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
                            .addComponent(preisTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
                            .addComponent(beschreibungTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
                            .addComponent(rankTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(18, 18, 18)
                        .addComponent(produktStatistikLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel12))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(startAuctionButton)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel9))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jSpinner1)
                                    .addComponent(auctionTTLSpinner, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE))))
                        .addGap(180, 180, 180)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(deleteButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(saveButton))
                            .addComponent(jLabelForIcon, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(idLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(preisTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(beschreibungTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rankTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(produktStatistikLabel)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(auctionTTLSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabelForIcon, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveButton)
                    .addComponent(deleteButton)
                    .addComponent(startAuctionButton))
                .addContainerGap())
        );

        newButton.setText(resourceMap.getString("newButton.text")); // NOI18N
        newButton.setName("newButton"); // NOI18N
        newButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newButtonActionPerformed(evt);
            }
        });

        sucheNameTextField.setText(resourceMap.getString("sucheNameTextField.text")); // NOI18N
        sucheNameTextField.setName("sucheNameTextField"); // NOI18N

        suchePreisTextField.setText(resourceMap.getString("suchePreisTextField.text")); // NOI18N
        suchePreisTextField.setName("suchePreisTextField"); // NOI18N

        searchButton.setText(resourceMap.getString("searchButton.text")); // NOI18N
        searchButton.setName("searchButton"); // NOI18N
        searchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchButtonActionPerformed(evt);
            }
        });

        RefreshButton.setText(resourceMap.getString("RefreshButton.text")); // NOI18N
        RefreshButton.setName("RefreshButton"); // NOI18N
        RefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RefreshButtonActionPerformed(evt);
            }
        });

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jSpinnerVonJahr.setName("jSpinnerVonJahr"); // NOI18N
        jSpinnerVonJahr.setRequestFocusEnabled(false);

        jSpinnerBisJahr.setName("jSpinnerBisJahr"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel6)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(suchePreisTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(searchButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(RefreshButton))
                            .addComponent(sucheNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel14)
                                    .addComponent(jLabel15))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 147, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jSpinnerBisJahr)
                                    .addComponent(jSpinnerVonJahr, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE))))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(newButton, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(7, 7, 7)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14)
                            .addComponent(jSpinnerVonJahr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(27, 27, 27)
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel10))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel15)
                                    .addComponent(jSpinnerBisJahr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(sucheNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(suchePreisTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(RefreshButton, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(searchButton))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(newButton))
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * ausgewähltes Produkt in der DetailView anzeigen
     * @param evt
     */
    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        Produkt p = produktModel.getRow((this.jTable1.getSelectedRow()));

        Logger.trace("Lade Produkt für DetailView");
        binder.BindTo(idLabel, Integer.toString(p.getID()));
        binder.BindTo(nameTextField, p.getName());
        binder.BindTo(preisTextField, Integer.toString(p.getPrice()));
        binder.BindTo(beschreibungTextField, p.getDescription());
        binder.BindTo(rankTextField, Integer.toString(p.getRequiredRank()));
        binder.BindTo(produktStatistikLabel, BusinessLayer.getProduktStatistik(p.getID()));
        if(p.getIcon() != null){
            binder.BindTo(jLabelForIcon, p.getIcon());
        }
        else{
            jLabelForIcon.setIcon(null);
        }
        


        //falls es der Panafonic ist darf man ihn nicht löschen
        if(p.getID() == 2){
            this.deleteButton.setEnabled(false);
        }
        else{
            this.deleteButton.setEnabled(true);
        }

    }//GEN-LAST:event_jTable1MouseClicked

    /**
     * Editiertes Produkt speichern
     * @param evt
     */
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        Produkt p = new Produkt();
        int countRank = BusinessLayer.getRankCount();
        RequiredRule rRule = new RequiredRule();
        GreaterThenRule gRule = new GreaterThenRule(0);
        binder.clearErrorList();
        Logger.debug("Clear Error List - binder");

        p.setID(binder.BindFromInt(idLabel, rRule));
        p.setName(binder.BindFromString(nameTextField, rRule));
        p.setDescription(binder.BindFromString(beschreibungTextField, rRule));
        p.setPrice(binder.BindFromInt(preisTextField, rRule, gRule));
        p.setRequiredRank(binder.BindFromInt(rankTextField, rRule, gRule));



        if(!binder.getHasErrors()){
            if(p.getRequiredRank() > countRank){
                Logger.user("Rang muss niedrieger sein als " + countRank);
            }
            else{
                BusinessLayer.updateItem(p);
                Logger.info("Speichere änderungen am Produkt");
                //alle Listen neu laden - es könnte sich etwas geändert haben
                WiSiView.refreshAll();
                Logger.debug("RefreshAll from " + this.getName());

            }
        }

        
}//GEN-LAST:event_saveButtonActionPerformed

    /**
     * ausgewähltes Produkt löschen
     * @param evt
     */
    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        Produkt p = new Produkt();
        RequiredRule rRule = new RequiredRule();
        GreaterThenRule gRule = new GreaterThenRule(0);
        binder.clearErrorList();
        Logger.debug("Clear Error List - binder");

        p.setID(binder.BindFromInt(idLabel, rRule));
        p.setName(binder.BindFromString(nameTextField, rRule));
        p.setDescription(binder.BindFromString(beschreibungTextField, rRule));
        p.setPrice(binder.BindFromInt(preisTextField, rRule, gRule));
        p.setRequiredRank(binder.BindFromInt(rankTextField, rRule, gRule));

        BusinessLayer.deleteItem(p);
        Logger.info("Lösche Produkt " + p.getName());
        WiSiView.refreshAll();
        Logger.debug("RefreshAll from " + this.getName());
    }//GEN-LAST:event_deleteButtonActionPerformed

    /**
     * öffnet einen Dialpg um ein neues Produkt zu erstellen
     * @param evt
     */
    private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
        NewProduct np = new NewProduct(WiSiApp.getApplication().getMainFrame(), true);
        np.setVisible(true);
        WiSiView.refreshAll();
        Logger.debug("RefreshAll from " + this.getName());
    }//GEN-LAST:event_newButtonActionPerformed

    /**
     * der Admin kann auktionen Starten um neue Produkte ins spiel zu bringen
     * hier wird dsa aktuelle Produkt zur auktion frei gegeben
     * @param evt
     */
    private void startAuctionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startAuctionButtonActionPerformed
        Produkt p = null;
        int amount = 0;
        int dauer = 0;

        try{
            p = produktModel.getRow(this.jTable1.getSelectedRow());
            amount = Integer.parseInt(this.jSpinner1.getValue().toString());
            dauer = Integer.parseInt(this.auctionTTLSpinner.getValue().toString());
            if(amount <= 0){
                Logger.user("Wählen Sie mehr als 0 Items");
            } else if(dauer <= 0){
                Logger.user("Wählen Sie mehr als 0 Stunden für die Auktion");
            } else{
                Logger.user("");
                // ausgewähltes Produkt für eine auktion frei gebenproduzieren
                int i = BusinessLayer.startAuctionAsAdmin(p, amount, dauer);
                switch(i){
                    case 1:
                        Logger.debug(p.getName() + " wurde für eine Auktion frei gegeben");
                        WiSiView.refreshAll();
                        break;
                    case -9033:
                        Logger.user("Auktion liegt in der Vergangenheit");
                        break;
                    case -9999:
                        Logger.user("-9999 - Fehler - Others in der DB");
                        break;
                    default:
                        Logger.user("Es geschah etwas unerwartetes");
                        break;
                }

                Logger.debug("RefreshAll from " + this.getName());

            }

        } catch(ArrayIndexOutOfBoundsException ex){
            Logger.user("Bitte ein Produkt auswählen");
        }
}//GEN-LAST:event_startAuctionButtonActionPerformed

    /**
     * der Admin hat eine Suchfunktion
     * @param evt
     */
    private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed

        //TODO: Preissuche, ist das das gewuenschte? Man sucht nach minimalem Preis?

        GreaterThenRule gRule = new GreaterThenRule(0);
        RequiredRule rRule = new RequiredRule();
        
        ArrayList<Produkt> list = new ArrayList<Produkt>();

        binder.clearErrorList();
        Logger.debug("Clear Error List - binder");

        if(this.suchePreisTextField.getText().isEmpty()){
            //suchen nach name
            list = BusinessLayer.searchItem(binder.BindFromString(sucheNameTextField, rRule));
            Logger.debug("Suche in Produkte nach Name");
        }
        else if(this.sucheNameTextField.getText().isEmpty()){
            //nach preis suchen
            list = BusinessLayer.searchItem(binder.BindFromInt(suchePreisTextField, gRule));
            Logger.debug("Suche in Produkte nach Preis");
        }
        else{
            list = BusinessLayer.searchItem(binder.BindFromString(sucheNameTextField, rRule), binder.BindFromInt(suchePreisTextField, gRule));
            Logger.debug("Suche in Produkte nach Name und Preis");
        }

        if(!binder.getHasErrors()){
            BindTo(list);
            Logger.user("");
        }
        
}//GEN-LAST:event_searchButtonActionPerformed

    /**
     * um nach einer Suche wieder Alle Produkte anzuzeigen
     * 
     * @param evt
     */
    private void RefreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RefreshButtonActionPerformed
        BindTo();
}//GEN-LAST:event_RefreshButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton RefreshButton;
    private javax.swing.JSpinner auctionTTLSpinner;
    private javax.swing.JTextField beschreibungTextField;
    private javax.swing.JButton deleteButton;
    private javax.swing.JLabel idLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelForIcon;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSpinner jSpinner1;
    private javax.swing.JSpinner jSpinnerBisJahr;
    private javax.swing.JSpinner jSpinnerVonJahr;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JButton newButton;
    private javax.swing.JTextField preisTextField;
    private javax.swing.JLabel produktStatistikLabel;
    private javax.swing.JTextField rankTextField;
    private javax.swing.JButton saveButton;
    private javax.swing.JButton searchButton;
    private javax.swing.JButton startAuctionButton;
    private javax.swing.JTextField sucheNameTextField;
    private javax.swing.JTextField suchePreisTextField;
    // End of variables declaration//GEN-END:variables

}
